package com.hengpeng.itfinoss.service.reward.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.common.persist.QueryResult;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.itfinbase.persist.Reward;
import com.hengpeng.itfinoss.service.ServiceFactory;
import com.hengpeng.itfinoss.service.reward.RewardService;

@Service
@Lazy
public class RewardServiceImpl implements RewardService {
    @Autowired
    private ServiceFactory serviceFactory;

    @Override
    public ServiceResult<List<Reward>> selectRewardPage(int indexPage, int pageSize) {

        DynamicQuery query = new DynamicQuery(Reward.class);
        query.setIsSearchTotalCount(true);
        query.setPageIndex(indexPage);
        query.setPageSize(pageSize);
        query.desc("rewardType");
        QueryResult<Reward> requery = serviceFactory.getPersistService().findWithPage(Reward.class, query);
        ServiceResult<List<Reward>> result = new ServiceResult<List<Reward>>(requery.getResults());
        result.setReturnListSize((int) requery.getTotalCount());
        return result;
    }

    @Override
    public Reward save(Reward reward) {
        return serviceFactory.getPersistService().save(reward);
    }

}
